
package ru.samgtu.wst.util.swing.treetable;

import javax.swing.tree.DefaultTreeModel;

import javax.swing.tree.TreeNode;


public class DefaultTreeTableModel extends DefaultTreeModel implements
		TreeTableModel {

	/**
	 * Creates a tree in which any node can have children.
	 * 
	 * @param root
	 *            a TreeNode object that is the root of the tree
	 * @see #DefaultTreeModel(TreeNode, boolean)
	 */
	public DefaultTreeTableModel(TreeNode root) {
		this(root, false);
	}

	/**
	 * Creates a tree specifying whether any node can have children, or whether
	 * only certain nodes can have children.
	 * 
	 * @param root
	 *            a TreeNode object that is the root of the tree
	 * @param asksAllowsChildren
	 *            a boolean, false if any node can have children, true if each
	 *            node is asked to see if it can have children
	 * @see #asksAllowsChildren
	 */
	public DefaultTreeTableModel(TreeNode root, boolean asksAllowsChildren) {
		super(root, asksAllowsChildren);
	}

	// TreeTable specific methods

	/**
	 * Returns the number of available columns.
	 */
	public int getColumnCount() {
		return 1;
	}

	/**
	 * Returns the name for column number <code>column</code>.
	 */
	public String getColumnName(int column) {
		return "A";
	}

	/**
	 * Returns the type for column number <code>column</code>.
	 */
	public Class getColumnClass(int column) {
		return column == 0 ? TreeTableModel.class : Object.class;
	}

	/**
	 * Returns the value to be displayed for node <code>node</code>, at column
	 * number <code>column</code>.
	 */
	public Object getValueAt(Object node, int column) {
		return column == 0 ? node : "Override getValueAt!!";
	}

	/**
	 * By default, make the column with the Tree in it the only editable one.
	 * Making this column editable causes the JTable to forward mouse and
	 * keyboard events in the Tree column to the underlying JTree.
	 */
	public boolean isCellEditable(Object node, int column) {
		return getColumnClass(column) == TreeTableModel.class;
	}

	/**
	 * Sets the value for node <code>node</code>, at column number
	 * <code>column</code>.
	 */
	public void setValueAt(Object aValue, Object node, int column) {
	}

}
